package com.finer.service.impl;

import com.finer.entity.finance.FinerMoneyPayDetail;
import com.finer.dao.FinerMoneyPayDetailDao;
import com.finer.service.FinerMoneyPayDetailService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 财务收款款详情表(FinerMoneyPayDetail)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:38
 */
@Service("finerMoneyPayDetailService")
public class FinerMoneyPayDetailServiceImpl implements FinerMoneyPayDetailService {
    @Resource
    private FinerMoneyPayDetailDao finerMoneyPayDetailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FinerMoneyPayDetail queryById(Integer id) {
        return this.finerMoneyPayDetailDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param finerMoneyPayDetail 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerMoneyPayDetail> queryByPage(FinerMoneyPayDetail finerMoneyPayDetail, PageRequest pageRequest) {
        long total = this.finerMoneyPayDetailDao.count(finerMoneyPayDetail);
        return new PageImpl<>(this.finerMoneyPayDetailDao.queryAllByLimit(finerMoneyPayDetail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerMoneyPayDetail 实例对象
     * @return 实例对象
     */
    @Override
    public FinerMoneyPayDetail insert(FinerMoneyPayDetail finerMoneyPayDetail) {
        this.finerMoneyPayDetailDao.insert(finerMoneyPayDetail);
        return finerMoneyPayDetail;
    }

    /**
     * 修改数据
     *
     * @param finerMoneyPayDetail 实例对象
     * @return 实例对象
     */
    @Override
    public FinerMoneyPayDetail update(FinerMoneyPayDetail finerMoneyPayDetail) {
        this.finerMoneyPayDetailDao.update(finerMoneyPayDetail);
        return this.queryById(finerMoneyPayDetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.finerMoneyPayDetailDao.deleteById(id) > 0;
    }
}
